function validateLoginForm()
{
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	
	document.getElementById("message").innerHTML = "";
	document.getElementById("userMsg").innerHTML = "";
	document.getElementById("pswMsg").innerHTML = "";
	
	if (username == "" || password == "") {
		
		if (username == "")
			document.getElementById("userMsg").innerHTML = "Inserire username";
		
		if (password == "")			
			document.getElementById("pswMsg").innerHTML = "Inserire password";
		return;
	}
	
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{ 
		xmlhttp = new XMLHttpRequest();
	}
	else // code for IE6, IE5
	{ 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			$response = xmlhttp.responseText;
			if (!strcmp($response, "ERR")) {
				document.getElementById("message").innerHTML = "Impossibile validare le " +
				"credenziali fornite";
				resetForm();
			} else if (!strcmp($response, "KO")) {
				document.getElementById("password").value = "";
				document.getElementById("userMsg").innerHTML = "";
				document.getElementById("pswMsg").innerHTML = "Password errata!";
			} else if (!strcmp($response, "NO")) {
				document.getElementById("message").innerHTML = "Non sei registrato.<br>" + 
				"Contatta un amministratore per ottenere le credenziali di accesso";
				resetForm();
			} else {
				window.location = "personal_page.php";
			}
		}
	}

	xmlhttp.open("POST", "php/ajax/verify_login.php", true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("username=" + username + "&password=" + password);
}

function resetForm() {
	document.getElementById("username").value = "";
	document.getElementById("password").value = "";
	document.getElementById("userMsg").innerHTML = "";
	document.getElementById("pswMsg").innerHTML = "";
}